﻿var totalPageNum = 1;
var jsonData;
var pageNode;
window.onload = function initProcessPage() {
	modifyCss();
	//ajaxGetSearchContent();
};

function modifyCss() {
	document.getElementById("rightTab").style.width = document.documentElement.clientWidth
			- 250 + "px";
};

function hasClass(obj, cls) {
	return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
};

function addClass(obj, cls) {
	if (!this.hasClass(obj, cls)) {
		obj.className += " " + cls;
	}
};

function removeClass(obj, cls) {
	if (hasClass(obj, cls)) {
		var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
		obj.className = obj.className.replace(reg, ' ');
	}
};

function getPrePage() {
	var prePage = parseInt(document.getElementById("currentPage").innerHTML) - 1;
	if (prePage > 0) {
		jsonData =ajaxSearch(pageNode,prePage);
		ajaxGetSearchContent();
		$("#currentPage").html(prePage);
	}
};

function getNextPage() {
	var nextPage = parseInt(document.getElementById("currentPage").innerHTML) + 1;
	if (nextPage <= totalPageNum) {
		jsonData =ajaxSearch(pageNode,nextPage);
		ajaxGetSearchContent();
		$("#currentPage").html(nextPage);
	}
};

function searchPageBtn() {
	var pageNum = document.getElementById("searchPageNum").value;
	if (pageNum != "" && pageNum <= totalPageNum) {
		jsonData =ajaxSearch(pageNode,pageNum);
		ajaxGetSearchContent();	}
};

function ajaxSearch(id,page) {
	var json="";
	$.ajax({
		type : "POST",
		datatyp : "json",
		data : {
			page : page,
			rows : 10,
			orgId : id
			
		},
		async : false,
		cache : false,
		url : "../../clientController.action?method=pageClient",
		success : function(data) {
			json = data;
			totalPageNum = data.pages;
			$("#pageToolNumTotal").html(data.total);
		}
	});
	return json;
	
}


function ajaxGetSearchContent() {
	
	var html = "";
	
	html += "<table class='table table-hover table-responsive' style='border-spacing:0px;'><thead><tr>";
	html += "<th class='thColor'>被授时终端名称</th>";
	html += "<th class='thColor'>被授时终端Ip</th>";
	html += "<th class='thColor'>单位名称</th>";
	html += "<th class='thColor'>时间服务器Ip</th>";
	html += "<th class='thColor'>状态</th>";
	html += "<th class='thColor'>时间</th>";
	html += "<th class='thColor'>类型</th>";
	html += "<th class='thColor'>重要等级</th>";
	html += "<th class='thColor'>时间偏差（秒）</th>";
	html += "<th class='thColor'>偏差警戒值（秒）</th>";
	html += "<th class='thColor'>操作</th>";
	html += "</tr></thead>";
	for ( var i = 0; i < jsonData.rows.length; i++) {
		html += "<tbody><tr>";
		html += "<td>" + jsonData.rows[i].name + "</td>";
		html += "<td>" + jsonData.rows[i].ip + "</td>";
		html += "<td>" + jsonData.rows[i].orgName + "</td>";
		html += "<td>" + jsonData.rows[i].clockIp + "</td>";
		html += "<td>" + "5" + "</td>";
		html += "<td>" + "6" + "</td>";
		html += "<td>" + "7" + "</td>";
		html += "<td>" + "8" + "</td>";
		html += "<td>" + "9" + "</td>";
		html += "<td>" + "10" + "</td>";
		html += "<td>";
		html += "<button type='button' class='btn btn-info btn-xs' onclick=''>修改</button>";
		html += "<button type='button' class='btn btn-warning btn-xs' style='margin-left:15px;' onclick=''>删除</button>";
		html += "</td>";
		html += "</tr>";
		html += "</tbody>";
	}
	html += "</table>";
	
	document.getElementById("searchContent").innerHTML = html;
};
